﻿using System;
using System.Collections.Generic;
using System.Web;
using OneMG.Phoenix.Service.Model;
using OneMG.Phoenix.Service.Contracts;
using OneMG.Phoenix.Service;
using OneMG.Phoenix.Kernel.Util;
using OneMG.Phoenix.Kernel.Enum;
using OneMG.Phoenix.Kernel.Helper;

namespace OneMG.Phoenix.AdminSite.Views.Product
{
 
    public class save : IHttpHandler
    {
        IProductPhotosService IProductPhotos = new ProductPhotosService();
        IProductService IProduct = new ProductService();

        
        public void ProcessRequest(HttpContext context)
        {
            int productid = 0;
            int.TryParse(context.Request.Form["productid"], out productid);
             
            //删除图片

            IList<ProductPhotosModel> modelList = IProductPhotos.GetListByProductID(productid);

            foreach (var item in modelList)
            {
                ImageHelper.DeleteFile(item.Photo);
            }
            IProductPhotos.DeleteByProductID(productid);
            IProduct.DeleteByProductID(productid);

            JsonResult.Result(context, JsonMessageStatus.OK, "删除成功!");

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
